package com.tfdy.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SqliteDao {


    /**
     * 根据类型查询点列表
     * @param type 类型污水、雨水
     * @param sourePath
     * @return
     */
    public List<Map<Integer,String>> getDianListMapByType(String type,String sourePath) {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement prep = null;
        List<Map<Integer,String>> list = new ArrayList<>();
        try {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:"+ sourePath);
            Statement stat = conn.createStatement();
            String querySql="";
            if(type.equals("污水")) {
                querySql = "select * from ksws_nod";
            }else if(type.equals("雨水")) {
                querySql = "select * from ksys_nod";
            }
            rs = stat.executeQuery(querySql);
            while (rs.next()) {
                Map<Integer,String> mapObj = new HashMap<>();
                int i = 0;
                mapObj.put(i++ , rs.getString("内业点号"));
                mapObj.put(i++ ,rs.getString("物探点号"));
                mapObj.put(i++ ,rs.getString("X坐标"));
                mapObj.put(i++ ,rs.getString("Y坐标"));
                mapObj.put(i++ ,rs.getString("地面高程"));
                mapObj.put(i++ ,rs.getString("井深"));
                mapObj.put(i++ ,rs.getString("组分类型"));
                mapObj.put(i++ ,rs.getString("几通"));
                mapObj.put(i++ ,rs.getString("附属物"));
                mapObj.put(i++ ,rs.getString("特征"));
                mapObj.put(i++ ,rs.getString("附属物规模"));
                mapObj.put(i++ ,rs.getString("修建年代"));
                mapObj.put(i++ ,rs.getString("探查时间"));
                mapObj.put(i++ ,rs.getString("测量单位"));
                mapObj.put(i++ ,rs.getString("竣工测量时间"));
                mapObj.put(i++ ,rs.getString("使用状态"));
                mapObj.put(i++ ,rs.getString("道路名称"));
                mapObj.put(i++ ,rs.getString("井盖尺寸"));
                mapObj.put(i++ ,rs.getString("井盖形状"));
                mapObj.put(i++ ,rs.getString("井底形式"));
                mapObj.put(i++ ,rs.getString("检查井等级"));
                mapObj.put(i++ ,rs.getString("图幅号"));
                mapObj.put(i++ ,rs.getString("备注"));
                mapObj.put(i++ ,rs.getString("管点归属"));
                mapObj.put(i++ ,rs.getString("埋设日期"));
                mapObj.put(i++ ,rs.getString("现场照片"));
                list.add(mapObj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs != null){
                    rs.close();
                }
                if(prep != null){
                    prep.close();
                }
                if(conn != null){
                    conn.close();
                }
            }catch (SQLException ex){
                ex.printStackTrace();
            }
        }
        return list;
    }


    /**
     * 根据类型查询管线列表
     * @param type 类型雨水、污水
     * @param sourePath 路径
     * @return
     */
    public List<Map<Integer,String>> getXianListMapByType(String type, String sourePath) {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement prep = null;
        List<Map<Integer,String>> list = new ArrayList<>();
        try {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:"+ sourePath);
            Statement stat = conn.createStatement();
            String querySql="";
            if(type.equals("污水")) {
                querySql = "select * from ksws_lin";
            }else if(type.equals("雨水")) {
                querySql = "select * from ksys_lin";
            }
            rs = stat.executeQuery(querySql);
            while (rs.next()) {
                Map<Integer,String> mapObj = new HashMap<>();
                int i = -1;
                mapObj.put(++i,rs.getString("管段编码"));
                mapObj.put(++i,rs.getString("起点点号"));
                mapObj.put(++i,rs.getString("终点点号"));
                mapObj.put(++i,rs.getString("混接编码"));
                mapObj.put(++i,rs.getString("管线类型"));
                mapObj.put(++i,rs.getString("埋设方式"));
                mapObj.put(++i,rs.getString("起点地面高程"));
                mapObj.put(++i,rs.getString("终点地面高程"));
                mapObj.put(++i,rs.getString("起点内底高程"));
                mapObj.put(++i,rs.getString("终点内底高程"));
                mapObj.put(++i,rs.getString("起点埋深"));
                mapObj.put(++i,rs.getString("终点埋深"));
                mapObj.put(++i,rs.getString("断面尺寸"));
                mapObj.put(++i,rs.getString("规格"));
                mapObj.put(++i,rs.getString("材质"));
                mapObj.put(++i,rs.getString("管长"));
                mapObj.put(++i,rs.getString("道路名称"));
                mapObj.put(++i,rs.getString("流向"));
                mapObj.put(++i,rs.getString("是否有压"));
                mapObj.put(++i,rs.getString("权属单位"));
                mapObj.put(++i,rs.getString("修建年代"));
                mapObj.put(++i,rs.getString("探查时间"));
                mapObj.put(++i,rs.getString("竣工测量时间"));
                mapObj.put(++i,rs.getString("测量单位"));
                mapObj.put(++i,rs.getString("管段位置"));
                mapObj.put(++i,rs.getString("使用状态"));
                mapObj.put(++i,rs.getString("录像编号1"));
                mapObj.put(++i,rs.getString("录像编号2"));
                mapObj.put(++i,rs.getString("图幅号"));
                mapObj.put(++i,rs.getString("传票号"));
                mapObj.put(++i,rs.getString("备注"));
                mapObj.put(++i,rs.getString("管线归属"));
                if(type.equals("雨水")) {
                    mapObj.put(++i,rs.getString("管径口径"));
                }
                mapObj.put(++i,rs.getString("现场照片"));
                list.add(mapObj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs != null){
                    rs.close();
                }
                if(prep != null){
                    prep.close();
                }
                if(conn != null){
                    conn.close();
                }
            }catch (SQLException ex){
                ex.printStackTrace();
            }
        }
        return list;
    }
}
